package com.cug.campus_sh_market_server.entity.vo

import com.fasterxml.jackson.annotation.JsonInclude
import io.swagger.annotations.ApiModel
import io.swagger.annotations.ApiModelProperty

@Suppress("FunctionName", "unused")
@ApiModel(value = "统一返回对象", description = "请求结果无论成功与否,都将返回此对象，请求结果将展现在其中")
@JsonInclude(JsonInclude.Include.NON_NULL)
class ResultData<T> @JvmOverloads constructor(

    /**
     * 返回信息
     */
    @ApiModelProperty(name = "返回信息") var msg: String? = "",

    /**
     * 返回状态
     */
    @ApiModelProperty(name = "返回状态") var status: String = "",

    /**
     * 返回对象
     */
    @ApiModelProperty(name = "返回对象") var data: T? = null,
    /**
     * 返回对象集合(若需要返回多个对象, 可使用此属性)
     */
    @ApiModelProperty(name = "返回对象集合(若需要返回多个对象, 可使用此属性)") var objs: Array<T>? = null
) {

    companion object {
        @JvmStatic
        @JvmOverloads
        fun <T> SUCCESS(msg: String? = ResultStatusEnum.SUCCESS.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.SUCCESS.status
            resultData.data = data
            return resultData
        }

        @JvmStatic
        @JvmOverloads
        fun <T> LOGIN_SUCCESS(msg: String? = ResultStatusEnum.LOGIN_SUCCESS.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.LOGIN_SUCCESS.status
            resultData.data = data
            return resultData
        }

        @JvmStatic
        @JvmOverloads
        fun <T> FAILED(msg: String? = ResultStatusEnum.FAILED.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.FAILED.status
            resultData.data = data
            return resultData
        }

        @JvmStatic
        @JvmOverloads
        fun <T> PERMISSION_DENIED(msg: String? = ResultStatusEnum.PERMISSION_DENIED.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.PERMISSION_DENIED.status
            resultData.data = data
            return resultData
        }

        @JvmStatic
        @JvmOverloads
        fun <T> LOGIN_FAILED(msg: String? = ResultStatusEnum.LOGIN_FAILED.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.LOGIN_FAILED.status
            resultData.data = data
            return resultData
        }

        @JvmStatic
        @JvmOverloads
        fun <T> AUTH_FAILED(msg: String? = ResultStatusEnum.AUTH_FAILED.msg, data: T? = null): ResultData<T> {
            val resultData = ResultData<T>()
            resultData.msg = msg
            resultData.status = ResultStatusEnum.AUTH_FAILED.status
            resultData.data = data
            return resultData
        }
    }


    fun setResultMsg(msg: String): ResultData<T> {
        this.msg = msg
        return this
    }

    fun setResultStatus(status: String): ResultData<T> {
        this.status = status
        return this
    }

    fun setResultData(data: T?): ResultData<T> {
        this.data = data
        return this
    }

    fun setMultiData(data: Array<T>?): ResultData<T> {
        objs = data
        return this
    }

    override fun toString(): String {
        return "ResultData(resultMsg='$msg', resultStatus='$status', obj=$data, objs=${objs?.contentToString()})"
    }


}
